<template>
    <table>
        <tr>
            <td>优惠券标题</td>
            <td>开始时间</td>
            <td>结束时间</td>
            <td>库存数量</td>
            <td>金额</td>
            <td>描述</td>
            <td>操作</td>
        </tr>
        <tr v-for="item in list">
            <td>{{item.title}}</td>
            <td>{{item.stime.substr(0,10)}}</td>
            <td>{{item.etime.substr(0,10)}}</td>
            <td>{{item.kcount}}</td>
            <td>{{item.ymoney}}</td>
            <td>{{item.mshu}}</td>
            <td><input type="button" value="下架" @click="del(item.id)"></td>
        </tr>
    </table>
<span>总共<span style="color: red;">{{ count }}</span>条数据,每页显示<span style="color: red;">{{ states.page }}</span>条,当前第<span style="color: red;">{{ states.index }}</span>/<span style="color: red;">{{ pcount }}</span>页</span>


    <input type="button" value="首页" @click="setpage('a')">
    <input type="button" value="上一页" @click="setpage('b')">
    <input type="button" value="下一页" @click="setpage('c')">
    <input type="button" value="尾页" @click="setpage('d')">
  </template>
  
  <script setup lang="ts">
  import{onMounted, reactive, toRefs} from 'vue'
  import axios from 'axios'
  import {useRouter,useRoute} from 'vue-router'
  const route=useRoute()
  const router=useRouter()

  let data=reactive({
    states:{
        index:1,
        page:2
    },
    count:0,
    pcount:0,
    list:[]
  })
  let{states,count,pcount,list} =toRefs(data)

  onMounted(()=>{
    getlist()
  })
//显示
  const getlist=()=>{
    let obj={
        index:states.value.index,
        page:states.value.page
    }
    axios({
        url:'/api/Store/GetDiscounts',
        method:'get',
        params:obj
    })
    .then(res=>{
        console.log(res)
        list.value=res.data.data;
        count=res.data.coco;
        pcount=res.data.promax;
    })
    .catch(err=>{
        console.log(err)
    })
  }
//分页
  const setpage=(val:any)=>{
    if(val=="a"){
    states.value.index=1;
    getlist()
}
if(val=="b"){
    states.value.index--;
    getlist()
}
if(val=="c"){
    states.value.index++;
    getlist()
}
if(val=="d"){
    states.value.index=pcount.value;
    getlist()
}
  }
//下架
  const del=(id:any)=>{
    if(confirm("确定下架吗?")){
        let obj={
        id:id
    }
    axios({
        url:'/api/Store/Delete',
        method:'get',
        params:obj
    })
    .then(res=>{
        if(res.data.data==1){
            alert("下架成功")
            getlist()
        }else{
            alert("下架失败")
        }
    })
    } 
  }
  </script>
  
  <style scoped>
  
  </style>